package cn.blbsz.shop.controller;

import cn.blbsz.shop.service.UserSigninService;
import cn.blbsz.shop.utils.R;
import cn.blbsz.shop.utils.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * Created by yipingdong on 2017/4/13.
 */
@Api(tags = "签到接口")
@RestController
public class UserSigninController {
    @Autowired
    private UserSigninService userSigninService;

    @GetMapping("/signin_info")
    @ApiOperation("获取签到信息")
    public R index() {
        try {
            String data = userSigninService.findSigninInfo(SecurityUtil.getCurrentUser().getUserId(), new Date());
            return R.ok().data(data);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return R.error();
    }

    @GetMapping("/signin")
    @ApiOperation("签到")
    public R signin() {
        try {
            String info = userSigninService.signin(SecurityUtil.getCurrentUser().getUserId(), new Date());
            return R.ok(info);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return R.error();
    }

}
